<?php
	class Login extends CI_Controller
    {
        public function __construct() {
            parent::__construct();
        }
        
        public function adminLogin()
        {
            $temp['message'] = "Vui lòng nhập Tên đăng nhập và Mật khẩu";
            $this->load->view('admin/login', $temp);
        }
        
        public function userLogin()
        {
            
        }

        public function DangNhap()
        {
            $username = $this->input->post('username');
            $password = $this->input->post('password');            
            if($username != "" && $password != "")
            {
                $this->load->model('admin/manageusers','user');
                $this->user->Username = $username;
                $this->user->Password = $password;
                $dataUser = $this->user->LoadThongTinNguoiDung(); 
                if(!empty($dataUser))
                {
                      foreach($dataUser->result() as $row)
                      {                        
                          $dataUserSS = array('validKey' => 'sasori_login', 'username' => $row->tendangnhap, 'validated' => true);
                          $this->session->set_userdata($dataUserSS);                        
                      }
                  echo 'true';
                }
                else echo 'false';
                 
            }
             else echo 'false';
        }

     public function DangXuat()
        {
            $this->session->unset_userdata('username');
            $this->session->unset_userdata('validKey');
            $this->session->set_userdata('validated', false);
            $this->load->view('admin/login');
        }
    }
?>